<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="goodsId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['goodsId', validatorRules.goodsId]" placeholder="请输入goodsId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="activityTags" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['activityTags']" placeholder="请输入activityTags"></a-input>
        </a-form-item>
        <a-form-item label="categoryId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['categoryId']" placeholder="请输入categoryId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="categoryName" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['categoryName']" placeholder="请输入categoryName"></a-input>
        </a-form-item>
        <a-form-item label="catIdsStr" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['catIdsStr']" placeholder="请输入catIdsStr"></a-input>
        </a-form-item>
        <a-form-item label="couponDiscount" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['couponDiscount']" placeholder="请输入couponDiscount" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="couponEndTime" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['couponEndTime']" placeholder="请输入couponEndTime" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="couponMinOrderAmount" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['couponMinOrderAmount']" placeholder="请输入couponMinOrderAmount" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="couponRemainQuantity" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['couponRemainQuantity']" placeholder="请输入couponRemainQuantity" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="couponStartTime" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['couponStartTime']" placeholder="请输入couponStartTime" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="couponTotalQuantity" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['couponTotalQuantity']" placeholder="请输入couponTotalQuantity" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="descTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['descTxt']" placeholder="请输入descTxt"></a-input>
        </a-form-item>
        <a-form-item label="goodsDesc" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['goodsDesc']" rows="4" placeholder="请输入goodsDesc"/>
        </a-form-item>
        <a-form-item label="goodsImageUrl" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['goodsImageUrl']" rows="4" placeholder="请输入goodsImageUrl"/>
        </a-form-item>
        <a-form-item label="goodsName" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['goodsName']" placeholder="请输入goodsName"></a-input>
        </a-form-item>
        <a-form-item label="goodsThumbnailUrl" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['goodsThumbnailUrl']" rows="4" placeholder="请输入goodsThumbnailUrl"/>
        </a-form-item>
        <a-form-item label="商品类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['goodsType']" placeholder="请输入商品类型" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="hasCoupon" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['hasCoupon']" placeholder="请输入hasCoupon" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="hasMallCoupon" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['hasMallCoupon']" placeholder="请输入hasMallCoupon" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="lgstTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['lgstTxt']" placeholder="请输入lgstTxt"></a-input>
        </a-form-item>
        <a-form-item label="mallCouponDiscountPct" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['mallCouponDiscountPct']" placeholder="请输入mallCouponDiscountPct" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="mallCouponEndTime" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['mallCouponEndTime']" placeholder="请输入mallCouponEndTime" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="mallCouponId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['mallCouponId']" placeholder="请输入mallCouponId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="mallCouponMaxDiscountAmount" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['mallCouponMaxDiscountAmount']" placeholder="请输入mallCouponMaxDiscountAmount" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="mallCouponMinOrderAmount" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['mallCouponMinOrderAmount']" placeholder="请输入mallCouponMinOrderAmount" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="mallCouponRemainQuantity" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['mallCouponRemainQuantity']" placeholder="请输入mallCouponRemainQuantity" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="mallCouponStartTime" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['mallCouponStartTime']" placeholder="请输入mallCouponStartTime" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="mallCouponTotalQuantity" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['mallCouponTotalQuantity']" placeholder="请输入mallCouponTotalQuantity" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="mallCps" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['mallCps']" placeholder="请输入mallCps" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="mallId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['mallId']" placeholder="请输入mallId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="店铺名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['mallName']" placeholder="请输入店铺名称"></a-input>
        </a-form-item>
        <a-form-item label="merchantType" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['merchantType']" placeholder="请输入merchantType" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="最小成团价格，单位分" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['minGroupPrice']" placeholder="请输入最小成团价格，单位分" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="最小单买价格，单位分" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['minNormalPrice']" placeholder="请输入最小单买价格，单位分" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="onlySceneAuth" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['onlySceneAuth']" placeholder="请输入onlySceneAuth" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="optId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['optId']" placeholder="请输入optId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="optIds" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['optIds']" rows="4" placeholder="请输入optIds"/>
        </a-form-item>
        <a-form-item label="optName" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['optName']" placeholder="请输入optName"></a-input>
        </a-form-item>
        <a-form-item label="planType" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['planType']" placeholder="请输入planType"></a-input>
        </a-form-item>
        <a-form-item label="佣金比例,千分比" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['promotionRate']" placeholder="请输入佣金比例,千分比" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="销售量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['salesTip']" placeholder="请输入销售量"></a-input>
        </a-form-item>
        <a-form-item label="searchId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['searchId']" rows="4" placeholder="请输入searchId"/>
        </a-form-item>
        <a-form-item label="serviceTags" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['serviceTags']" placeholder="请输入serviceTags"></a-input>
        </a-form-item>
        <a-form-item label="servTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['servTxt']" placeholder="请输入servTxt"></a-input>
        </a-form-item>
        <a-form-item label="zsDuoId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['zsDuoId']" placeholder="请输入zsDuoId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="0:默认，1推荐" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['type']" placeholder="请输入0:默认，1推荐" style="width: 100%"/>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  
  export default {
    name: "PddGoodsRecommendModal",
    components: { 
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          goodsId: {
            rules: [
              { required: true, message: '请输入goodsId!'},
            ]
          },
        },
        url: {
          add: "/pdd/pddGoodsRecommend/add",
          edit: "/pdd/pddGoodsRecommend/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'goodsId','activityTags','categoryId','categoryName','catIdsStr','couponDiscount','couponEndTime','couponMinOrderAmount','couponRemainQuantity','couponStartTime','couponTotalQuantity','descTxt','goodsDesc','goodsImageUrl','goodsName','goodsThumbnailUrl','goodsType','hasCoupon','hasMallCoupon','lgstTxt','mallCouponDiscountPct','mallCouponEndTime','mallCouponId','mallCouponMaxDiscountAmount','mallCouponMinOrderAmount','mallCouponRemainQuantity','mallCouponStartTime','mallCouponTotalQuantity','mallCps','mallId','mallName','merchantType','minGroupPrice','minNormalPrice','onlySceneAuth','optId','optIds','optName','planType','promotionRate','salesTip','searchId','serviceTags','servTxt','zsDuoId','type'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'goodsId','activityTags','categoryId','categoryName','catIdsStr','couponDiscount','couponEndTime','couponMinOrderAmount','couponRemainQuantity','couponStartTime','couponTotalQuantity','descTxt','goodsDesc','goodsImageUrl','goodsName','goodsThumbnailUrl','goodsType','hasCoupon','hasMallCoupon','lgstTxt','mallCouponDiscountPct','mallCouponEndTime','mallCouponId','mallCouponMaxDiscountAmount','mallCouponMinOrderAmount','mallCouponRemainQuantity','mallCouponStartTime','mallCouponTotalQuantity','mallCps','mallId','mallName','merchantType','minGroupPrice','minNormalPrice','onlySceneAuth','optId','optIds','optName','planType','promotionRate','salesTip','searchId','serviceTags','servTxt','zsDuoId','type'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>